var layer = require('layer');
var tpl = require('../../views/editform');
var request = require('request');
var template = require('template');
var editform = require('./editform');

var _layer = function(data){
    var that = this;
    layer({
        content:template.render(tpl, data||{}),
        width:420,
        title:!data ? '新增账套' : '修改账套',
        cancel:{
            enable:false
        },
        button:[{
            id:'confirm',
            name:'blue',
            text:!data ? '创建账套' : '确定修改'
        }],
        onInit:function(self){
            editform.call(that, self.element, self);
            self.resize();
        }
    })
}

return function(e, elem, data){
    var that = this;
    if(data){
        request.get('account/get', data, function(res){
            _layer.call(that, res.data.account)
        })
    }
    else{
        _layer.call(that)
    }
}